home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!txwang
- From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
- Newsgroups: comp.lang.c++
- Subject: Re: Dynamically initializing static members
- Date: Sat, 23 Mar 1996 18:37:08 GMT
- Message-ID: <199603230651.OAA15366@public1.guangzhou.gd.cn>
- X-NNTP-Posting-Host: txwang
- X-Newsreader: Forte Free Agent 1.0.82
- X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
-
- On 22 Mar 1996 10:11:18 GMT, apardon@rc1.vub.ac.be (Antoon Pardon)
- wrote:
-
- | I am playing with the idea of somekind of classregistration.
-
- | The registration class would provide for a function:
-
- | unsigned int Registrate(const char *name);
-
- | This would keep the name of the function stored somewhere and
- | would return a registration ID.
-
- | The idea would be to include a static int into the class that
- | would store this ID something like this
-
- | class MYCLASS {
- | static unsigned int
- | Registration_ID
-
- | ...
-
- | }
-
- | The problem now is how do I assign this Registration_ID
- | automatically. In Modula 2 you have initialisation code
- | that is called at the start of the program where you might
- | then put code similar to
-
- | MYCLASS::Registration_D = Registrate("MYCLASS");
-
- | Is something similar possible in C++ or do I have to
- | do it in a different way? I looked at the FAQ but
- | couldn't find an answer there.
-
- If you write the line as
-
- unsigned int MYCLASS::Registration_ID = Registrate("MYCLASS");
-
- it should work. If it really doesn't work, buy a better compiler.
-
- ---
- Wang TianXing
-
-
-